﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MrDev.Graphics;
using MrDev.Physics;

namespace MrDev.GameObjects
{
    class Powerup : GameObject
    {
        private Animation animation;
        public enum Powerups
        {
            Disc = 0
        }

        public Powerups PowerupType;
        float time;
        Vector2 basePosition;
        float radius = 5;
        public Powerup(Level level, Vector2 position, Powerups type, float randomTime)
            : base(level)
        {
            this.PowerupType = type;
            this.Level = level;
            Parameters = PhysicsParameters.CreatePowerupParameters();
            SetColor(Color.White);

            time = randomTime;
            int reminder = (int)(randomTime / (Math.PI * 2f));
            time = time - (float)((float)reminder * Math.PI * 2f);
            basePosition = position;
            LoadContent(type);
            Level.Physics.SetObjectPosition(this, position);
            PlayAnimation(animation);
        }

        private void LoadContent(Powerups type)
        {
            // Load animated textures.
            string contentFile = string.Empty;
            switch (type)
            {
                case Powerups.Disc:
                    contentFile = "powerup_disk";
                    break;

            }

            animation = new Animation(Level.Content.Load<Texture2D>("Sprites/Powerups/"+contentFile), 0.1f, false, (int)type, 1);
        }

        public override void Update(GameTime gameTime)
        {
            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
            float pi2 = (float)Math.PI * 2f;
            Parameters.Position.X = basePosition.X + radius*(float)Math.Cos(10*time);
            Parameters.Position.Y = basePosition.Y + radius*(float)Math.Sin(12*time);
            time += elapsedTime;
            if (time > pi2)
                time -= pi2;

        }

       
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            base.Draw(gameTime, spriteBatch);
        }


    }
}
